package com.juc.singtontest;

/**
 * @author yuanzheng
 * @date 2020/8/14-21:17
 */
public class LazyMan {
    private static LazyMan lazyMan;

    private LazyMan() {
        System.out.println(Thread.currentThread().getName() + "-getIt!");
    }

    public static LazyMan getInstance() {
        if (lazyMan == null) {
            lazyMan = new LazyMan();
        }
        return lazyMan;
    }

    // 多线程会出现问题
    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                LazyMan.getInstance();
            }).start();
        }
    }
}
